package com.woniu.consumer;

import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.woniu.model.AllRoomnum;
import com.woniu.service.AllRoomnumService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 新增房间数据到 数据库 的消费者
 */
@Component
@RabbitListener(queues = "roomNum_queue")
public class RoomNumConsumer {
    @Resource
    private AllRoomnumService allRoomnumService;
    @RabbitHandler
    public void insertMessage(Map<String, Object> map) throws JsonProcessingException {
        AllRoomnum allRoomnum = BeanUtil.mapToBean(map, AllRoomnum.class, true, null);
        System.out.println("消息队列执行数据库新增操作allRoomnum");
        System.out.println(allRoomnum);
        allRoomnumService.save(allRoomnum);
    }
}
